/**
 * @module  event
 * @author	zfkun<zfkun@msn.com>
 * 
 * @method
 * 		add
 * 		adds
 * 		remove
 * 		removes
 * 		stop
 * 		stop
 * 		prevent
 */
ZF.add('event', function(Z) {

	var ADD_EVENT_LISTENER = 'addEventListener',
		ATTACH_EVENT = 'attachEvent',
		REMOVE_EVENT_LISTENER = 'removeEventListener',
		DETACH_EVENT = 'detachEvent',
		PREVENT_DEFAULT = 'preventDefault',
		STOP_PROPAGATION = 'stopPropagation',
		CANCEL_BUBBLE = 'cancelBubble',
		RETURN_VALUE = 'returnValue';

    Z.Event = {
	
        adds : function(element, events) {
            for (var type in events) this.add(el, type, events[type]);
            return this;
        },
        
        add : function(element, type, fn, capture) {
            if(element) element[ADD_EVENT_LISTENER] ? element[ADD_EVENT_LISTENER](type, fn, capture || false) : element[ATTACH_EVENT]('on' + type, fn);
            return this;
        },
        
        removes : function(el, events) {
            for (var type in events) this.remove(el, type, events[type]);
            return this;
        },
        
        remove : function(element, type, fn, capture) {
            if(element) element[REMOVE_EVENT_LISTENER] ? element[REMOVE_EVENT_LISTENER](type, fn, capture || false) : element[DETACH_EVENT]('on' + type, fn);
            return this;
        },
        
        stop : function(e) {
            return this.stopPropagation(e).prevent(e);
        },
        
        stopPropagation : function(e) {
            e = e || window.event;
            if (e) {
                e[STOP_PROPAGATION] ? e[STOP_PROPAGATION]() : e[CANCEL_BUBBLE] = true;
            }
            return this;
        },
        
        prevent : function(e) {
            e = e || window.event;
            if (e) {
                e[PREVENT_DEFAULT] ? e[PREVENT_DEFAULT]() : e[RETURN_VALUE] = false;
            }
            return this;
        }

    };

});